<?php

/**
 * @version			$Id$
 * @create 			2015-04-21 01:04:46 By xjiujiu
 * @description     HongJuZi Framework
 * @copyRight 		Copyright (c) 2011-2012 http://www.xjiujiu.com.All right reserved
 */
defined('_HEXEC') or die('Restricted access!');

//导入引用文件
HClass::import('config.popo.advpopo, app.admin.action.AdminAction, model.advmodel');

/**
 * 大图展示的动作类 
 * 
 * 主要处理后台管理主页的相关请求动作 
 * 
 * @author 			xjiujiu <xjiujiu@foxmail.com>
 * @package 		app.admin.action
 * @since 			1.0.0
 */
class AdvAction extends AdminAction
{

    /**
     * 构造函数 
     * 
     * 初始化类变量 
     * 
     * @access public
     */
    public function __construct() 
    {
        parent::__construct();
        $this->_catIdentifier   = 'cat-adv';
        $this->_popo        = new AdvPopo();
        $this->_model       = new AdvModel($this->_popo);
    }

    /**
     * 做一些其他的任务 
     * 
     * @access protected
     */
    protected function _otherJobsAfterInfo()
    {
        parent::_otherJobsAfterInfo();
        HResponse::setAttribute('is_show_list', AdvPopo::$isShowMap);
        HResponse::setAttribute('parent_id_list', $this->_getParentIdMap());
    }

    /**
     * 得到分类编号映射 
     * 
     * @return [type] [description]
     */
    private function _getParentIdMap()
    {
        $staticCfg          = HClass::quickLoadModel('staticcfg');
        $where              = '`identifier` LIKE \'adv-parent-id-map%\'';
        $advParentIdMapList = $staticCfg->getAllRowsByFields(
            '`id`, `content`',
            $where
        );
        foreach($advParentIdMapList as $item) {
            $advParentIdMap         = json_decode(HString::decodeHtml($item['content']), true);
            AdvPopo::$parentIdMap   = array_merge(AdvPopo::$parentIdMap, $advParentIdMap);
        }

        return AdvPopo::$parentIdMap;
    }

    /**
     * 编辑前的动作
     */
    protected function _otherJobsBeforeEdit()
    {
        parent::_otherJobsBeforeEdit();
        HRequest::setParameter('start_time', strtotime(HRequest::getParameter('start_time')));
        HRequest::setParameter('end_time', strtotime(HRequest::getParameter('end_time')));
        HRequest::setParameter('lang_id', HSession::getAttributeByDomain('curLangInfo')['id']);
        HRequest::setParameter('uniacid', HSession::getAttribute('acid', 'curWeiXinInfo'));
    }

    /**
     * 加载完列表的方法
     *
     * @return [type] [description]
     */
    protected function _otherJobsAfterList()
    {
        parent::_otherJobsAfterList();
        $this->_registerIsShowFormatMap();
        HResponse::$formatDateTimeMap['start_time']     = 'Y-m-d H:i:s';
        HResponse::$formatDateTimeMap['end_time']       = 'Y-m-d H:i:s';
    }

    /**
     * 注册上下架map
     */
    protected function _registerIsShowFormatMap()
    {
        $parentIdList   = $this->_getParentIdMap();
        HResponse::registerFormatMap('is_show', 'name', AdvPopo::$isShowMap);
        HResponse::registerFormatMap('parent_id', 'name', $parentIdList);
        HResponse::setAttribute('parent_id_list', $parentIdList);
    }

}

?>
